package org.flexharmony.eclipse.nature.wizard;

import static org.flexharmony.eclipse.utils.CommonMethods.*;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;

public class AddProjectNatureWizard extends Wizard implements INewWizard
{
  IProject project;
  
  private PropertiesPage propertiesPage;
  
  private SourceInclusionPage inclusionPage;
  
  private boolean addNature;
  
  public AddProjectNatureWizard(IProject project)
  {
    this.project = project;
    setWindowTitle("Add FlexHarmony Nature");
  }

  public void init(IWorkbench workbench, IStructuredSelection selection)
  {
    
  }

  @Override
  public void addPages()
  {
    propertiesPage = new PropertiesPage();
    addPage(propertiesPage);
    
    inclusionPage = new SourceInclusionPage();
    addPage(inclusionPage);
  }

  @Override
  public boolean canFinish()
  {
    return (getContainer().getCurrentPage() == inclusionPage);
  }

  @Override
  public boolean performFinish()
  {
    try
    {
      propertiesPage.save();
      inclusionPage.save();
      addNature = true;
      return true;
    }
    catch (CoreException cexc)
    {
      cexc.printStackTrace();
      return false;
    }
  }
  
  public boolean addProjectNature()
  {
    return addNature;
  }
}
